<template>
    <h3>新增年级</h3>
    <a-form :model="grade" name="basic" :label-col="{ span: 4 }" :wrapper-col="{ span: 16 }" autocomplete="off"
        @finish="handleClick">
        <a-form-item label="年级名称" name="gradeName" 
        :rules="[{ required: true, message: '请输入年级' }]">
            <a-input v-model:value="grade.gradeName" />
        </a-form-item>

        <a-form-item :wrapper-col="{ offset: 8, span: 16 }">
            <a-button type="primary" html-type="submit">Submit</a-button>
        </a-form-item>
    </a-form>
</template>
<script>
import axios from 'axios';
export default {
    data() {
        return {
            grade: {
                gradeID: '',
                gradeName: ''
            }
        }
    },
    methods: {
        handleClick() {
            axios.post('/grade/', {
                gradeName: this.grade.gradeName
            }).then(res => {
                if (res.data.success) {
                    alert('添加成功')
                    let grade = res.data.data
                    this.grade.gradeID = grade.gradeID
                }
            })
        }
    }
}
</script>
<style scoped></style>